package com.weather.web.business;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.weather.common.annotation.Log;
import com.weather.common.core.controller.BaseController;
import com.weather.common.core.domain.AjaxResult;
import com.weather.common.enums.BusinessType;
import com.weather.business.domain.NmShop;
import com.weather.business.service.INmShopService;
import com.weather.common.utils.poi.ExcelUtil;
import com.weather.common.core.page.TableDataInfo;

/**
 * 商城Controller
 *
 * @author ruoyi
 * @date 2024-03-16
 */
@RestController
@RequestMapping("/business/shop")
public class NmShopController extends BaseController
{
    @Autowired
    private INmShopService nmShopService;

    /**
     * 查询商城列表
     */
    @PreAuthorize("@ss.hasPermi('business:shop:list')")
    @GetMapping("/list")
    public TableDataInfo list(NmShop nmShop)
    {
        startPage();
        List<NmShop> list = nmShopService.selectNmShopList(nmShop);
        return getDataTable(list);
    }

    /**
     * 导出商城列表
     */
    @PreAuthorize("@ss.hasPermi('business:shop:export')")
    @Log(title = "商城", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, NmShop nmShop)
    {
        List<NmShop> list = nmShopService.selectNmShopList(nmShop);
        ExcelUtil<NmShop> util = new ExcelUtil<NmShop>(NmShop.class);
        util.exportExcel(response, list, "商城数据");
    }

    /**
     * 获取商城详细信息
     */
    @PreAuthorize("@ss.hasPermi('business:shop:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(nmShopService.selectNmShopById(id));
    }

    /**
     * 新增商城
     */
    @PreAuthorize("@ss.hasPermi('business:shop:add')")
    @Log(title = "商城", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody NmShop nmShop)
    {
        return toAjax(nmShopService.insertNmShop(nmShop));
    }

    /**
     * 修改商城
     */
    @PreAuthorize("@ss.hasPermi('business:shop:edit')")
    @Log(title = "商城", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody NmShop nmShop)
    {
        return toAjax(nmShopService.updateNmShop(nmShop));
    }

    /**
     * 删除商城
     */
    @PreAuthorize("@ss.hasPermi('business:shop:remove')")
    @Log(title = "商城", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(nmShopService.deleteNmShopByIds(ids));
    }
}
